﻿'//DotNetNuke - http://www.dotnetnuke.com
'// Copyright (c) 2002-2010
'// by DotNetNuke Corporation
'//
'// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
'// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
'// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
'// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'//
'// The above copyright notice and this permission notice shall be included in all copies or substantial portions
'// of the Software.
'//
'// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
'// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
'// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
'// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
'// DEALINGS IN THE SOFTWARE.
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Content

Namespace Components
    Public Class Article
        Inherits ContentItem

        Private _articleId As Integer
        Private _title As String
        Private _description As String
        Private _body As String
        Private _createdByUserId As Integer
        Private _lastModifiedByUserId As Integer
        Private _createdOnDate As DateTime
        Private _lastModifiedOnDate As DateTime
        Private _moduleId As Integer
        Private _portalId As Integer
        Private _totalRecords As Integer

        Public Property ArticleId() As Integer
            Get
                Return _articleId
            End Get
            Set(ByVal value As Integer)
                _articleId = value
            End Set
        End Property


        Public Property Title() As String
            Get
                Return _title
            End Get
            Set(ByVal value As String)
                _title = value
            End Set
        End Property

        Public Property Description() As String
            Get
                Return _description
            End Get
            Set(ByVal value As String)
                _description = value
            End Set
        End Property
        Public Property Body() As String
            Get
                Return _body
            End Get
            Set(ByVal value As String)
                _body = value
            End Set
        End Property

        Public Overloads Property CreatedByUserId() As Integer
            Get
                Return _createdByUserId
            End Get
            Set(ByVal value As Integer)
                _createdByUserId = value
            End Set
        End Property

        Public Overloads Property LastModifiedByUserId() As Integer
            Get
                Return _lastModifiedByUserId
            End Get
            Set(ByVal value As Integer)
                _lastModifiedByUserId = value
            End Set
        End Property

        Public Overloads Property CreatedOnDate() As DateTime
            Get
                Return _createdOnDate
            End Get
            Set(ByVal value As DateTime)
                _createdOnDate = value
            End Set
        End Property
        Public Overloads Property LastModifiedOnDate() As DateTime
            Get
                Return _lastModifiedOnDate
            End Get
            Set(ByVal value As DateTime)
                _lastModifiedOnDate = value
            End Set
        End Property

        Public Overloads Property ModuleId() As Integer
            Get
                Return _moduleId
            End Get
            Set(ByVal value As Integer)
                _moduleId = value
            End Set
        End Property

        Public Property PortalId() As Integer
            Get
                Return _portalId
            End Get
            Set(ByVal value As Integer)
                _portalId = value
            End Set
        End Property

        Public Overloads ReadOnly Property CreatedByUser() As String
            Get
                If CreatedByUserId > 0 Then
                    Return Null.NullString
                End If
                Return Entities.Users.UserController.GetUserById(PortalId, CreatedByUserId).Username
            End Get
        End Property

        Public Overloads ReadOnly Property LastUpdatedByUser() As String
            Get
                If CreatedByUserId > 0 Then
                    Return Null.NullString
                End If
                Return Entities.Users.UserController.GetUserById(PortalId, CreatedByUserId).Username
            End Get
        End Property


        Public Property TotalRecords() As Integer
            Get
                Return _totalRecords
            End Get
            Set(ByVal value As Integer)
                _totalRecords = value
            End Set
        End Property




        Public Sub Save(ByVal tabId As Integer)
            ArticleId = ArticleController.SaveArticle(Me, tabId)
        End Sub


        Public Overrides Sub Fill(ByVal dr As System.Data.IDataReader)
            MyBase.FillInternal(dr)

            ArticleId = Null.SetNullInteger(dr("Id"))
            ModuleId = Null.SetNullInteger(dr("ModuleId"))
            Title = Null.SetNullString(dr("Title"))
            Description = Null.SetNullString(dr("Description"))
            Body = Null.SetNullString(dr("Body"))
            CreatedByUserId = Null.SetNullInteger(dr("CreatedByUserId"))
            LastModifiedByUserId = Null.SetNullInteger(dr("LastModifiedByUserId"))
            CreatedOnDate = Null.SetNullDateTime(dr("CreatedOnDate"))
            LastModifiedOnDate = Null.SetNullDateTime(dr("LastModifiedOnDate"))

            TotalRecords = Null.SetNullInteger(dr("TotalRecords"))

        End Sub

        Public Overrides Property KeyID() As Integer
            Get
                Return ArticleId
            End Get
            Set(ByVal value As Integer)
                ArticleId = value
            End Set
        End Property

    End Class
End Namespace